//package com.warmlight.voicepacket.fragment;
//
//import android.content.Intent;
//import android.os.Bundle;
//import android.support.annotation.Nullable;
//import android.support.design.widget.TabLayout;
//import android.support.v4.view.ViewPager;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.ViewGroup;
//import android.widget.TextView;
//
//import com.warmlight.voicepacket.CommentDetailAcitivity;
//import com.warmlight.voicepacket.PostDetailsActivity;
//import com.google.gson.Gson;
//import com.warmlight.voicepacket.R;
//import com.warmlight.voicepacket.adapter.CommunityPagerAdapter;
//import com.warmlight.voicepacket.adapter.TopicPagerAdapter;
//import com.warmlight.voicepacket.base.BaseFragment;
//import com.warmlight.voicepacket.data.RecommendData;
//import com.warmlight.voicepacket.http.HttpClient;
//import com.warmlight.voicepacket.http.HttpConfig;
//import com.warmlight.voicepacket.http.HttpUtils;
//import com.warmlight.voicepacket.http.ResponseData;
//import com.warmlight.voicepacket.widget.CoverLoading;
//
//import java.util.ArrayList;
//import java.util.List;
//import java.util.TreeMap;
//
//import io.reactivex.android.schedulers.AndroidSchedulers;
//import io.reactivex.functions.Consumer;
//
///**
// * Created by jason on 2018/8/22.
// */
//
//public class CommunityFragment extends BaseFragment {
//
//    private CoverLoading cover;
//    private TabLayout tl_community;
//    private ViewPager vp_community;
//    private CommunityPagerAdapter mCommunityAdapter;
//    private List<RecommendData.DataBean.CategoryBean> tabList = new ArrayList<>();
//
//    @Nullable
//    @Override
//    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//
//        mView = inflater.inflate(R.layout.fragment_community, container, false);
//        mView = View.inflate(getActivity(),R.layout.fragment_community, null);
////        Intent intent=new Intent(getActivity(), CommentDetailAcitivity.class);
////                    startActivity(intent);
//        initView();
//        getData();
//
//        return mView;
//    }
//
//    private void initView(){
//
//
//        cover = (CoverLoading) findViewById(R.id.loading);
//        cover.setVisibility(View.VISIBLE);
//        cover.setOnReloadClickListener(new CoverLoading.ReloadListener() {
//            @Override
//            public void onReloadClicked() {
//                getData();
//            }
//        });
//        cover.setResult(CoverLoading.LoadingResult.LOADING);
//
//        tl_community = (TabLayout) findViewById(R.id.tl_community);
//        vp_community = (ViewPager) findViewById(R.id.vp_community);
//        tl_community.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
//            @Override
////<<<<<<< HEAD
////            public void onClick(View v) {
////                //TODO 去你自己的页面，临时用完或者修改后记得Revert
////                    Intent intent=new Intent(getActivity(), PostDetailsActivity.class);
////                    startActivity(intent);
//////                CommunityShare share = new CommunityShare();
//////                share.show(getChildFragmentManager(),"share");
////=======
//            public void onTabSelected(TabLayout.Tab tab) {
//                vp_community.setCurrentItem(tab.getPosition());
//            }
//
//            @Override
//            public void onTabUnselected(TabLayout.Tab tab) {
//            }
//
//            @Override
//            public void onTabReselected(TabLayout.Tab tab) {
//            }
//        });
//
//        vp_community.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
//            @Override
//            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
//            }
//
//            @Override
//            public void onPageSelected(int position) {
//                if (tl_community.getSelectedTabPosition() != position) {
//                    tl_community.getTabAt(position).select();
//                }
//            }
//
//            @Override
//            public void onPageScrollStateChanged(int state) {
//            }
//        });
//    }
//
//    /**
//     * 获取服务器数据
//     */
//    private void getData(){
//        HttpClient.getInstance().postRxAndroidAES(HttpConfig.SERVER+HttpConfig.DISCOVER,new TreeMap<String, String>())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Consumer<ResponseData>() {
//                    @Override
//                    public void accept(ResponseData responseData) throws Exception {
//                        if (HttpUtils.isCodeSuccess(responseData.getCode())){
//                            final RecommendData data = new Gson().fromJson(responseData.getBody(),RecommendData.class);
//
//                            if(data.getData() == null){
//                                if(cover!=null){
//                                    cover.setResult(CoverLoading.LoadingResult.NULL);
//                                }
//                                return;
//                            }
//
////                            tabList = data.getData().getCategory();
//                            tabList = jiashuju();
//
//                            fillTopic(tl_community,tabList);
//                            mCommunityAdapter = new CommunityPagerAdapter(getContext(), tabList);
//                            vp_community.setAdapter(mCommunityAdapter);
//                            if(cover!=null){
//                                cover.setResult(CoverLoading.LoadingResult.SUCCESS);
//                            }
//                        }else{
//                            if(cover!=null){
//                                cover.setResult(CoverLoading.LoadingResult.NULL);
//                            }
//                        }
//                    }
//                }, new Consumer<Throwable>() {
//                    @Override
//                    public void accept(Throwable throwable) throws Exception {
//                        if(cover!=null){
//                            cover.setResult(CoverLoading.LoadingResult.FAIL);
//                        }
//                    }
//                });
//    }
//
//    //填充topic数据
//    private void fillTopic(TabLayout tl, List<RecommendData.DataBean.CategoryBean> list) {
//        if(tl!=null){
//            tl.removeAllTabs();
//        }
//        for (RecommendData.DataBean.CategoryBean temp : list) {
//            tl.addTab(tl.newTab().setText(temp.getName()));
//        }
//    }
//
//    /**
//     * 删除吧，假数据用
//     */
//    private List<RecommendData.DataBean.CategoryBean> jiashuju(){
//        List<RecommendData.DataBean.CategoryBean> delList = new ArrayList<>();
//        RecommendData.DataBean.CategoryBean temp1 = new RecommendData.DataBean.CategoryBean();
//        temp1.setId("1");
//        temp1.setName("推荐");
//        delList.add(temp1);
//        RecommendData.DataBean.CategoryBean temp2 = new RecommendData.DataBean.CategoryBean();
//        temp2.setId("2");
//        temp2.setName("视频");
//        delList.add(temp2);
//        RecommendData.DataBean.CategoryBean temp3 = new RecommendData.DataBean.CategoryBean();
//        temp3.setId("3");
//        temp3.setName("图文");
//        delList.add(temp3);
//
//        return delList;
//    }
//}
